package ah.ddh.test;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class LeiA {
	public static void main(String[] args) {

		String s = "is a &Mwertya not.\n";
		byte buf[] = s.getBytes();
		ByteArrayInputStream in = new ByteArrayInputStream(buf);
		BufferedInputStream f = new BufferedInputStream(in);
		int c;
		boolean marked = false;
		try {
			while ((c = f.read()) != -1) {

				switch (c) {
				case '&':
					if (!marked) {
						f.mark(3);// 为什么mark里放任何值结果都一样
						marked = true;
					} else {
						marked = false;
					}
					break;

				case ' ':
					if (marked) {

						f.reset();
						System.out.print("&");
					} else
						System.out.print((char) c);
					break;

				default:
					if (marked)
						System.out.print((char) c);
					break;
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}
}